﻿#region License

// Another free, open solution by folks who get it.
// Copyright © 2011 Business in Unison, Inc.
// 
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

#endregion

using System;

using FizzWare.NBuilder;

using FluentAssertions;

using Patterns.Threading;

using TechTalk.SpecFlow;

namespace Patterns.Specifications
{
	[Binding]
	public class GeneralSteps : BaseStepDefinition
	{
		public const string ResultKey = "general.result";
		public const string ObjectKey = "general.object";

		public static ComplexTestObject CurrentTestObject
		{
			get { return Get<ComplexTestObject>(ObjectKey); }
			set { Set(value, ObjectKey); }
		}

		public static object CurrentResult
		{
			get { return Get<object>(ResultKey); }
			set { Set(value, ResultKey); }
		}

		[Given(@"I have created a complex test object")]
		public void CreateTestObject()
		{
			CurrentTestObject = Builder<ComplexTestObject>.CreateNew().Build();
		}

		[When(@"I wait (\d+) millisecond(?:s)?")]
		public void Wait(int milliseconds)
		{
			TimeSpan.FromMilliseconds(milliseconds).Wait();
		}

		[Then(@"the result should be null")]
		public void AssertResultIsNull()
		{
			CurrentResult.Should().BeNull();
		}

		[Then(@"the test object and the retrieved object should be the same")]
		public void AssertResultMatchesOriginal()
		{
			CurrentResult.Should().BeSameAs(CurrentTestObject);
		}
	}
}